import React from 'react';
import classNames from 'classnames';

export default ({
                  src, width = 375, previewWidth = 50, isLazy = true, setRef = () => {
  }, ...other
                }) => {
  const cls = classNames({'lazyload': isLazy});
  const props = {
    src: isLazy ? `${src}?imageView2/0/w/${previewWidth}` : src
  };
  if (isLazy) {
    props['data-src'] = `${src}?imageView2/0/w/${width}`;
    props['data-sizes'] = 'auto';
  }
  return (
    <img
      className={cls}
      {...props}
      ref={setRef}
      {...other}
    />
  )
}